//
//  SCTableView.m
//  sooc-ios_new
//
//  Created by 郭琦 on 16/8/16.
//  Copyright © 2016年 SOOC. All rights reserved.
//

#import "SCTableView.h"
#import "UIScrollView+EmptyDataSet.h"
#import "DSFooterView.h"

@interface SCTableView ()<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>

@property (nonatomic, strong) NSString *emptyTitle;
@property (nonatomic, strong) UIImage *emptyImage;

@property (nonatomic, strong) DSFooterView *noMoreFoot;

@end

@implementation SCTableView

-(instancetype)init{
    self = [super init];
    
    if (self) {
        
        self.backgroundColor = BGC;
    }
    
    return self;
    
}

-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    self = [super initWithFrame:frame style:style];
    
    if (self) {

        self.backgroundColor = BGC;
    }
    
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        self.backgroundColor = BGC;
        
    }
    
    return self;
    
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    
    if (self) {
        self.backgroundColor = BGC;
    }
    return self;
    
}
#pragma mark - Empty

- (void)emptyWithTitle:(NSString *)title image:(UIImage *)image{
    if (self.emptyDataSetSource == nil) {
        self.emptyDataSetSource = self;
    }
    if (self.emptyDataSetDelegate == nil) {
        self.emptyDataSetDelegate = self;
    }
    
    self.emptyTitle = title;
    self.emptyImage = image;
    
}


#pragma mark Refresh
- (void)showNoMore{
    self.tableFooterView = self.noMoreFoot;
}


#pragma mark EmptyDataSet DataSource
-(NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
    
    //富文本对象
    NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:self.emptyTitle];
    
    //富文本样式
    [aAttributedString addAttribute:NSForegroundColorAttributeName  //文字颜色
                              value:Color999999
                              range:NSMakeRange(0, self.emptyTitle.length)];
    
    [aAttributedString addAttribute:NSFontAttributeName             //文字字体
                              value:[UIFont systemFontOfSize:10.0f]
                              range:NSMakeRange(0, self.emptyTitle.length)];
    
    return aAttributedString;
}


-(UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
    return self.emptyImage;
}
-(CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{
    return -20.0f;
}

#pragma mark - EmptyDataSet Delegate
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
{
    return self.showEmpty;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView
{
    return YES;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}

#pragma mark - SET &  GET

-(void)setShowEmpty:(BOOL)showEmpty{
    _showEmpty = showEmpty;
    
    [self reloadEmptyDataSet];
    
}

-(NSString *)emptyTitle{
    if (!_emptyTitle) {
        _emptyTitle = @"暂时没有信息哦~";
    }
    return _emptyTitle;
}

- (DSFooterView *)noMoreFoot{
    if (!_noMoreFoot) {
        _noMoreFoot = [[DSFooterView alloc]initWithFrame:CGRectMake(0, 0, SIZEWIDTH, 40)];
    }
    return _noMoreFoot;
}


@end
